package hiram.util.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import hiram.util.bean.User;

public class UserDao {
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	public void open() throws SQLException {
		conn = new EmbDataSource().getConnection();
		pstmt = conn.prepareStatement("insert into TB_USER(name,password) values(?,?)");
	}

	public void insert(User user) throws SQLException {
		pstmt.setString(1, user.getName());
		pstmt.setString(2, user.getPassword());
		pstmt.addBatch();
	}
	public void flush() throws SQLException{
		if (pstmt != null) {
			pstmt.executeBatch();
		}
	}
	public void close() throws SQLException {
		try {
			flush();
		} finally {
			if (pstmt != null)
				pstmt.close();
			if (conn != null)
				conn.close();
		}
	}
}
